Vim: `cd` to path stored in variable
Posted
by
tsyu80
on Stack Overflow
See other posts from Stack Overflow
or by tsyu80
Published on 2011-01-04T18:16:12Z
Indexed on
2011/01/04
18:53 UTC
Read the original article
Hit count: 87
vim
I'm pretty new to vim, and I'm having a hard time understanding some subtleties with vim scripting. Specifically, I'm having trouble working with commands that expect an unquoted-string (is there a name for this?). For example
cd some/unquoted/string/path
The problem is that I'd like to pass a variable, but calling
let pathname = 'some/path'
cd pathname
will try to change the current directory to 'pathname' instead of 'some/path'. One way around this is to use
let cmd = 'cd ' . pathname
execute cmd
but this seems a bit roundabout. This StackOverflow question actually uses cd
with a variable, but it doesn't work on my system ("a:path" is treated as the path as described above).
I'm using cd
as a specific example, but this behavior isn't unique to cd
; for example, the edit
command also behaves this way. (Is there a name for this type of command?)
© Stack Overflow or respective owner